package in.abip.chisame.model;

import android.R.integer;

/**
 * Abstract class for all active record that represent channel.
 * 
 * @author Julot.
 * @since Wednesday, January 26th, 2011.
 */
public abstract class AbstractChannel extends CActiveRecord {
	public Integer roomId = null;
	public Integer host = null;
	public Integer channel = null;
	public Integer typeId = null;
	public String name = null;
	public Boolean hasRange = false;
	
	protected static final Integer MAX_VALUE = 100;
	
	/**
	 *  Indicating that setValue never called.
	 *  Used to show Unknown state for getValueName.
	 */
	protected Boolean _virgin = true;
	
	/**
	 * Value.
	 */
	protected Integer _value = 0;
	
	/**
	 * Toggle value.
	 * When user use toggle method, save last value to use when user use toggle
	 * method again.
	 */
	protected Integer _toggleValue = 0;
	
	/**
	 * Get value.
	 * @return {@link Integer} the value.
	 */
	public abstract Integer getValue();
	
	/**
	 * Set value.
	 * @param value {@link integer}
	 */
	public abstract void setValue(Integer value);
	
	/**
	 * Get command to ask for value of the device.
	 * @return String the command.
	 */
	public String getAskCmd() {
		return Integer.toString(host + 100).substring(1) + 
			Integer.toString(100 + channel).substring(1) + "?";
	}
	
	/**
	 * Get command to set value of the device.
	 * @return String the command.
	 */
	public String getRunCmd() {
		return Integer.toString(100 + host).substring(1) + 
			Integer.toString(100 + channel).substring(1) + 
			Integer.toString(getValue() + 1000).substring(1);
	}
}
